package xyz.xiaoshengfu.xrpc.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.AbstractApplicationContext;

import xyz.xiaoshengfu.xrpc.data.XRpcResources;

/**
 * <p>Title: XRpcSpringApplicationListener</p>
 * <p>Description: 监听Spring加载配置文件完成，目的是启动xRPC</p>
 * @author xiaoshengfu(2439323118@qq.com)
 * @date 2020年3月24日
 */
public class XRpcSpringApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

	@Override
	public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
		ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
		//System.out.println(applicationContext.getClass().getName());
		if (applicationContext.getParent() == null) {
			//System.out.println(XRpcResources.xRpcConfig);
			XRpcResources.abstractApplicationContext = (AbstractApplicationContext) applicationContext;
			XRpcResources.init();
		}

	}
}
